# try:
#     print(5/0)
# except ZeroDivisionError:
#     print('You can not divide by zero.')
#
# print('Give me to numbers,and I will divide them.')
# print("Enter 'q' to quit.")
#
# while True:
#     first_number = input('\nFirst number:')
#     if first_number == 'q':
#         break
#     second_number = input('\nSecond number:')
#     if second_number == 'q':
#         break
#     try:
#         answer = int(first_number)/int(second_number)
#     except Exception as e:
#         #raise Exception('异常错误!')
#         print('异常为：',e)
#     else:
#         print(answer)


# 处理FileNotFoundError异常
try:
    with open(r'D:\uu\hello\pi_digits.txt','r') as file:
        contents = file.readlines()
except FileNotFoundError:
#except Exception as e:
    print('文件路径不存在！')

title = 'Alice in Wonderland'
s = title.split()
print(s)




def count_words(filename):
    '''计算一个文件大致包含多少个单词'''
    try:
        with open(filename,encoding='utf-8') as f:
            words = f.read()
    except Exception as e:
        # pass 静默失败
        print('异常为：',e)
    else:
        # 计算该文件包含多少个单词
        cs = words.split()
        new_cs = len(cs)
        print(f"This file {filename} has about {new_cs} words.")

filenames = ['alice.txt', 'siddhartha.txt', 'moby_dick.txt', 'little_women.txt']
for filename in filenames:
    count_words(filename)

a = ['123','456']
print(len(a))

